package com.yanqu.road.server.cmd.union.cross.trade;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.union.UnionTradeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.PropertyHelper;


@Cmd(code = Protocol.S_UNION_TRADE_ROUTE_OPEN_FROM_CROSS, desc = "开启路线")
public class TradeRouteOpenCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {


        UnionTradeProto.RouteOpenCrossRespMsg respMsg = UnionTradeProto.RouteOpenCrossRespMsg.parseFrom(packet.getBytes());

        player.getModule(PreReduceModule.class).restorePreReduce(respMsg.getConsume());

        if(respMsg.getRet() == 0){
            player.getModule(CurrencyModule.class).removeCurrency(PropertyHelper.parseStringToProperty(respMsg.getConsume()), eLogMoneyType.Union, eLogMoneyType.UnionTradeRouteOpen);
            DataAnalyticsMgr.trackOreWarOpenRoad(player, respMsg.getRouteId());
        }

        UnionTradeProto.RouteOpenRespMsg.Builder routeOpenResp = UnionTradeProto.RouteOpenRespMsg.newBuilder();
        routeOpenResp.setRet(respMsg.getRet());
        if(routeOpenResp.hasRouteMsg()){
            routeOpenResp.setRouteMsg(respMsg.getRouteMsg());
        }
        player.sendPacket(Protocol.U_UNION_TRADE_ROUTE_OPEN, routeOpenResp);

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
